﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSP.Model.CSP;
using System.Data.Entity.ModelConfiguration;

namespace CSP.DataAccess.Mapping
{
    public class StudentInfoMap : EntityTypeConfiguration<StudentInfo>
    {
        public StudentInfoMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(50);

            this.Property(t => t.Email)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.OrderNumber)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("StudentInfo");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Mobile).HasColumnName("Mobile");
            this.Property(t => t.Email).HasColumnName("Email");
            this.Property(t => t.OrderNumber).HasColumnName("OrderNumber");

            // Relationships
            this.HasRequired(t => t.Order)
                .WithMany(t => t.StudentInfoes)
                .HasForeignKey(d => d.OrderNumber);
        }
    }
}
